﻿using NiceManage.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Util.Helpers;

namespace NiceManage.Common
{
    public class Login:DbHelper
    {
        SqlSugar.SqlSugarClient db = GetInstance();

        public bool VerifyPas(string username, string password)
        {
          
            var entity= db.Queryable<m_user>().Where(a=>a.username==username).First();
          
            var pas= Encrypt.Md5By16(password);
            if (entity is null || entity.password!=pas)
            {
                return false;
            }
            return true;
        }

        public bool Register(string username, string password)
        {
            var entity = new m_user() {username=username,password=Encrypt.Md5By16(password),status=true,email=$"{username}@ithuo.net" };
            db.Insertable<m_user>(entity).ExecuteCommand();
            return true;
        }
    }
}
